//
//  YKQAddViewController.m
//  YaoKongQi
//
//  Created by ryou on 2021/5/19.
//
#define kBtnIconArray @[@"ykq_btn_kaiguan.png",@"ykq_btn_zidong.png",@"ykq_btn_shuimian.png",@"ykq_btn_chuifeng.png",@"ykq_btn_zhileng.png",@"ykq_btn_dingshi.png"]
#import "YKQAddViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>
#import "YKQMoreViewController.h"
@interface YKQAddViewController ()
@property(nonatomic,strong)AVAudioPlayer *movePlayer;
@end

@implementation YKQAddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"添加遥控器";
    
    UIImageView *headView=[[UIImageView alloc]initWithFrame:CGRectMake(20, 100, kYKQWidth  - 40, 120)];
    headView.image = [UIImage imageNamed:@"ykq_icon_white_bg.png"];
    headView.contentMode=UIViewContentModeScaleToFill;
    [self.view addSubview:headView];
    headView.userInteractionEnabled=YES;
    UIButton *moreBtn=[[UIButton alloc]initWithFrame:CGRectMake(headView.frame.size.width - 20 - 40, 40 , 40, 40)];
    [moreBtn setImage:[UIImage imageNamed:@"ykq_icon_gengduo.png"] forState:UIControlStateNormal];
    [moreBtn addTarget:self action:@selector(moreBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:moreBtn];
    
    UIImageView *icon=[[UIImageView alloc]init];
    icon.image = [UIImage imageNamed:@"ykq_icon_duankailianjie.png"];
    icon.frame = CGRectMake(30, headView.frame.size.height/2 - 20, 40, 40);
    [headView addSubview:icon];
    
    UILabel *nameLabel=[[UILabel alloc]initWithFrame:CGRectMake(icon.frame.size.width + icon.frame.origin.x + 20, 15, 300, headView.frame.size.height/2 -15)];
    nameLabel.text =  @"红外设备";
    nameLabel.textColor=kRedColor;
    [headView addSubview:nameLabel];
    nameLabel.font=[UIFont systemFontOfSize:18];
    
    UILabel *tipsLabel=[[UILabel alloc]initWithFrame:CGRectMake(icon.frame.size.width + icon.frame.origin.x + 20, headView.frame.size.height/2, 300, headView.frame.size.height/2 -15)];
    tipsLabel.text =  @"当前状态：未连接";
    tipsLabel.textColor=kBlackColor;
    [headView addSubview:tipsLabel];
    tipsLabel.font=[UIFont systemFontOfSize:16];
    
//    [NSTimer scheduledTimerWithTimeInterval:5.0 repeats:NO block:^(NSTimer * _Nonnull timer) {
//     // 需要延迟执行的代码
//         tipsLabel.text =  @"当前状态：已连接";
//        icon.hidden=YES;
//        moreBtn.hidden=YES;
//    }];
    
    UILabel *wenduLable=[[UILabel alloc]initWithFrame:CGRectMake(0, headView.frame.size.height  + headView.frame.origin.y + 20, kYKQWidth, 100)];
    wenduLable.text =  @"26°c";
    wenduLable.textColor=kRedColor;
    [self.view addSubview:wenduLable];
    wenduLable.textAlignment=NSTextAlignmentCenter;
    wenduLable.font=[UIFont systemFontOfSize:80];
    
    
    CGFloat itemW  = 100;
    CGFloat space = (kYKQWidth - itemW * 3)/4;
    for (int i=0; i  < kBtnIconArray.count ; i++) {
        
        UIButton  *button=[[UIButton alloc]initWithFrame:CGRectMake(space +(space+itemW)*(i%3),wenduLable.frame.size.height+ wenduLable.frame.origin.y + (itemW + space)*(i/3), itemW, itemW)];
        [button setImage:[UIImage imageNamed:kBtnIconArray[i]] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(ykqBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button];
        //        button.backgroundColor=[UIColor redColor];
        button.tag = i;
    }
    
    UIButton *doneBtn=[[UIButton alloc]initWithFrame:CGRectMake(kYKQWidth / 2  - 100,wenduLable.frame.size.height+ wenduLable.frame.origin.y + (itemW + space)*(2),  200, 74)];
    [doneBtn  setImage:[UIImage imageNamed:@"ykq_icon_white_bg.png"] forState:UIControlStateNormal];
    [doneBtn addTarget:self action:@selector(ykqBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [doneBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
    doneBtn.titleLabel.font=[UIFont boldSystemFontOfSize:25];
    [self.view addSubview:doneBtn];
    doneBtn.userInteractionEnabled=NO;
    
    UIImageView *jian=[[UIImageView alloc]initWithFrame:CGRectMake(20, 17, 40, 40)];
    jian.image=[UIImage imageNamed:@"ykq_icon_jian.png"];
    [doneBtn addSubview:jian];
    
    UIImageView *jia=[[UIImageView alloc]initWithFrame:CGRectMake(doneBtn.frame.size.width - 40 - 20, 17, 40, 40)];
    jia.image=[UIImage imageNamed:@"ykq_icon_jia.png"];
    [doneBtn addSubview:jia];
    
    [self ykqBUAdLoadBanner];

//    UIBarButtonItem *rightbtn=[[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStyleDone target:self action:@selector(done)];
//    self.navigationItem.rightBarButtonItem=rightbtn;
    // Do any additional setup after loading the view.
}
-(void)done{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
-(void)ykqBtnClick:(UIButton *)btn{
    //    NSInteger tag = btn.tag;
    [self movplaye];
}

-(void)moreBtnClick{
    YKQMoreViewController *more = [[YKQMoreViewController alloc]init];
    [self.navigationController pushViewController:more animated:YES];
}

-(void)movplaye{
    NSString *tmp = [[NSBundle mainBundle]pathForResource:@"ykq_tips" ofType:@"mov"];
    NSLog(@"%@",tmp);
    NSURL*moveMP3=[NSURL fileURLWithPath:tmp];
//    NSError*err=nil;
//    self.movePlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:moveMP3 fileTypeHint:nil error:&err];
//    self.movePlayer.volume=1.0;
//    [self.movePlayer prepareToPlay];
//    if(err!=nil) {
//        NSLog(@"move player init error:%@",err);
//    }else{
//        [self.movePlayer play];
//    }
    
    
//    AVPlayerItem * songItem = [[AVPlayerItem alloc]initWithURL:moveMP3];
//    AVPlayer * player = [[AVPlayer alloc]initWithPlayerItem:songItem];
//    [player play];
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
